import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
const routes = [
	{
		path: '/',
		redirect: '/home',
		component:() => import('../components/header.vue'),
		children: [
			{
				path: '/home',
				name: 'home',
				meta: { icon: 'ios-search', title: '首页' },
				component: () => import('../views/Home.vue')
			},
			{
				path: '/user',
				name: 'user',
				meta: { icon: 'ios-search', title: '用户管理' },
				component: () => import('../views/User.vue')
			},
			{
				path: '/push',
				name: 'push',
				meta: { icon: 'ios-search', title: '用户收藏详情' },
				component: () => import('../views/Push.vue')
			},
		]
	},

	{
		path: '/login',
		name: 'login',
		component: () => import('../views/Login.vue')
	}
]

const router = new VueRouter({
	mode: 'history',
	routes
})

// router.beforeEach((to, from, next) => {

// 	// 获取vuex中state的数据
// 	var isAuthenticated = router.app.$options.store.state.user
// 	if (isAuthenticated) next()
// 	else if (to.name !== 'login' && !isAuthenticated) next({ name: 'login' })
// 	else next()
// })
export default router
